package cn.edu.ecut.scheduling;

public class SleepRunnable implements Runnable {

	@Override
	public void run() {
		for( int i = 1 ; i < 6 ; i++ ) {
			System.out.println( Thread.currentThread() + " : " + i );
			try {
				// 线程睡眠后会释放CPU从让其它线程有机会获得CPU时间片
				Thread.sleep( 100 );
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
	
	public static void main(String[] args) {
		
		// 创建线程任务对应的对象
		Runnable r = new SleepRunnable();
		
		Thread t = new Thread( r , "first" ); // 创建第一个线程
		t.start();
		
		Thread h = new Thread( r , "second" ); // 创建第二个线程
		h.start();
		
	}

}
